import ProblemTypeModel from '../models/problemTypeModel';
import ajaxAsync from '../../../utils/ajaxAsync';

/**
 * 模拟类型数据
 *
 * @returns {Promise}
 */
function mockType() {
  let list = [
    new ProblemTypeModel('1', '刷码乘车', false),
    new ProblemTypeModel('2', '公交信息不准确', false),
    new ProblemTypeModel('3', '城市服务', false),
    new ProblemTypeModel('4', 'APP故障', false),
    new ProblemTypeModel('5', 'APP改进建议', false),
    new ProblemTypeModel('6', '其他', false)
  ]
  return new Promise((resolve) => {
    setTimeout(function() {
      resolve(list)
    }, 500)
  })
}
/**
 * 获取oss信息
 *
 * @returns {Promise}
 */
function getOssDec() {
  return ajaxAsync('/oss/policy/image', {}).then(res => {
    return {
      bucket: res.BUCKET,
      endpoint: res.END_POINT,
      ossPath: res.DIR
    }
  })
}
/**
 * 获取反馈类型
 *
 * @returns {Promise}
 */
function getFeedbackType() {
  // return mockType()
  return ajaxAsync('/user/subroute_feedback/types', {}).then(res => {
    let btnlist = res.LIST.map(
      i => new ProblemTypeModel(i.TYPE_ID, i.TYPE, false)
    )
    return btnlist
  })
}
/**
 * 添加线路意见反馈
 *
 * @param {Number} segmentId 支线上下行编号
 * @param {String} typeId 意见类型
 * @param {String} typeDec 意见类型描述
 * @param {String} content 意见内容
 * @param {Array} imgList 图片列表
 * @param {String} phoneNumber 联系手机号
 * @returns {Promise}
 */
function addLineFeedback(
  segmentId,
  typeId,
  typeDec,
  content,
  imgList,
  phoneNumber
) {
  return ajaxAsync('/user/subroute_feedback/add', {
    SEGMENT_ID: segmentId,
    TYPE_ID: typeId,
    TYPE: typeDec,
    PIC_LIST: imgList,
    CONTENT: content,
    PHONE_NO: phoneNumber
  })
}
export { addLineFeedback, getFeedbackType, mockType, getOssDec }
